package com.office.automate.servlet.report;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.office.automate.configuration.property.ReportPageConfiguration;
import com.office.automate.dto.convertors.ReportDetailsConvertor;
import com.office.automate.model.report.EmployeeLeaveDetailsRequest;

/**
 * Servlet implementation class EmployeeLeaveDetailsReportServlet
 */
@WebServlet("/EmployeeLeaveDetailsReportServlet")
public class EmployeeLeaveDetailsReportServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EmployeeLeaveDetailsReportServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/report/LeaveApplyDetailsReport.jsp");
		EmployeeLeaveDetailsRequest employeeLeaveDetailsRequest = new ReportDetailsConvertor().convertLeaveDetailRequest(request);
		request.setAttribute("RequestDetails", employeeLeaveDetailsRequest);
		request.setAttribute("ReportPageID", ReportPageConfiguration.EMPLOYEE_LEAVE_DETAILS_REPORT);
		if (employeeLeaveDetailsRequest.getLeaveReportType().equals("summaryDetail")) {
			dispatcher = getServletContext().getRequestDispatcher("/jsp/report/LeaveApplySummaryDetailsReport.jsp");
		}

		dispatcher.forward(request, response);
	}
}
